<UserControl x:Class="EdiApp.Views.Shell.MainToolbar"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    mc:Ignorable="d" 

    xmlns:vm="clr-namespace:EdiApp.Enums"

    xmlns:conv="clr-namespace:Edi.Core.Converters;assembly=Edi.Core"
    xmlns:adconv="clr-namespace:EdiDocuments.Converter;assembly=EdiDocuments"
    xmlns:avalonEdit="clr-namespace:ICSharpCode.AvalonEdit.Highlighting;assembly=ICSharpCode.AvalonEdit"
    xmlns:cmd="clr-namespace:Edi.Core;assembly=Edi.Core"
    xmlns:cmdLabel="clr-namespace:Util.Local;assembly=Util"
    xmlns:behav="clr-namespace:Edi.Core.Behaviour;assembly=Edi.Core"

    xmlns:ctrls="clr-namespace:DropDownButtonLib.Controls;assembly=DropDownButtonLib"
    xmlns:themes="clr-namespace:DropDownButtonLib.Core.Themes;assembly=DropDownButtonLib"
  
		Visibility="{Binding IsWorkspaceAreaOptimized, Converter={conv:BoolToVisibilityConverter}, ConverterParameter=true}">
  <!--d:DesignHeight="300" d:DesignWidth="300"-->
  <UserControl.Resources>
    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
  </UserControl.Resources>
  <Grid>
    <ToolBarTray Grid.Row="1" SnapsToDevicePixels="True">
      <ToolBar  VerticalAlignment="Stretch" ToolBarTray.IsLocked="True"
                SnapsToDevicePixels="True"
                behav:HideToolbarOverflowButton.HideGrip="True">

        <Button Command="New" SnapsToDevicePixels="True"
                ToolTip="{x:Static cmdLabel:Strings.STR_CmdName_New_Text_TT}"
                ToolTipService.ShowOnDisabled="True"
								FocusVisualStyle="{x:Null}">
          <Image Source="{DynamicResource Image_New}" Height="32" SnapsToDevicePixels="True" />
        </Button>

        <ctrls:SplitItemsButton ToolTip="{Binding Path=SelectedOpenDocumentType.Description,FallbackValue='Open different file types'}"
                                ItemsSource="{Binding DocumentTypes}"
                                Command="Open"
                                CommandParameter="{Binding SelectedOpenDocumentType, Mode=OneWay}"
                                DropDownMaxHeight="300"
                                HorizontalAlignment="Left"
																FocusVisualStyle="{x:Null}"
                              >
          <ctrls:SplitItemsButton.Content>
            <Grid>
              <Image Source="{DynamicResource Image_Open}" Height="32" Margin="0"/>
              <!-- Image Source="pack://application:,,,/Themes;component/Images/Documents/document.png" Height="16" Margin="0"/ -->
            </Grid>
          </ctrls:SplitItemsButton.Content>
          <ctrls:DropDownItemsButton.ItemTemplate>
            <DataTemplate>
              <Grid>
                <Button Command="Open"
                        CommandParameter="{Binding Key, Mode=OneWay}"
                        Margin="0"
                        Padding="3"
                        HorizontalAlignment="Left"
                        VerticalAlignment="Center"
												FocusVisualStyle="{x:Null}"
                        >
                  <StackPanel>
                    <Image Source="{DynamicResource Image_Open}" Height="32" SnapsToDevicePixels="True"
                           ToolTip="{Binding Description, Mode=OneWay}" />
                  </StackPanel>
                </Button>
              </Grid>
            </DataTemplate>
          </ctrls:DropDownItemsButton.ItemTemplate>
        </ctrls:SplitItemsButton>

        <Button Command="Save" SnapsToDevicePixels="True"
                ToolTip="{x:Static cmdLabel:Strings.STR_CmdName_Save_TT}"
                ToolTipService.ShowOnDisabled="True"
								FocusVisualStyle="{x:Null}">
          <Image Source="{DynamicResource Image_Save}" Height="32" SnapsToDevicePixels="True" />
        </Button>

        <Button Command="SaveAs" SnapsToDevicePixels="True"
                ToolTip="{x:Static cmdLabel:Strings.STR_CmdName_SaveAs_TT}"
                ToolTipService.ShowOnDisabled="True"
								FocusVisualStyle="{x:Null}">
          <Image Source="{DynamicResource Image_SaveAs}" Height="32" SnapsToDevicePixels="True" />
        </Button>

        <Button Command="cmd:AppCommand.SaveAll" SnapsToDevicePixels="True"
                ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}"
								FocusVisualStyle="{x:Null}">
          <Image Source="{DynamicResource Image_SaveAll}" Height="32" SnapsToDevicePixels="True" />
        </Button>

        <Separator Margin="9,3" SnapsToDevicePixels="True" />

        <Button Command="Copy" SnapsToDevicePixels="True"
                ToolTip="{x:Static cmdLabel:Strings.STR_CmdName_Copy_TT}"
                ToolTipService.ShowOnDisabled="True"
								FocusVisualStyle="{x:Null}">
          <Image Source="{DynamicResource Image_Copy}" Height="32" SnapsToDevicePixels="True" />
        </Button>

        <Button Command="Cut" SnapsToDevicePixels="True"
                ToolTip="{x:Static cmdLabel:Strings.STR_CmdName_Cut_TT}"
                ToolTipService.ShowOnDisabled="True"
								FocusVisualStyle="{x:Null}">
          <Image Source="{DynamicResource Image_Cut}" Height="32" SnapsToDevicePixels="True" />
        </Button>

        <Button Command="Paste" SnapsToDevicePixels="True"
                ToolTip="{x:Static cmdLabel:Strings.STR_CmdName_Paste_TT}"
                ToolTipService.ShowOnDisabled="True"
								FocusVisualStyle="{x:Null}">
          <Image Source="{DynamicResource Image_Paste}" Height="32" SnapsToDevicePixels="True" />
        </Button>

        <Button Command="Delete" SnapsToDevicePixels="True"
                ToolTip="{x:Static cmdLabel:Strings.STR_CmdName_Delete_TT}"
                ToolTipService.ShowOnDisabled="True"
								FocusVisualStyle="{x:Null}">
          <Image Source="{DynamicResource Image_Delete}" Height="32"/>
        </Button>

        <Separator Margin="9,3"/>

        <Button Command="Undo" SnapsToDevicePixels="True"
                ToolTip="{x:Static cmdLabel:Strings.STR_CmdName_Undo_TT}"
                ToolTipService.ShowOnDisabled="True"
								FocusVisualStyle="{x:Null}">
          <Image Source="{DynamicResource Image_Undo}" Height="32"/>
        </Button>

        <Button Command="Redo" SnapsToDevicePixels="True"
                ToolTip="{x:Static cmdLabel:Strings.STR_CmdName_Redo_TT}"
                ToolTipService.ShowOnDisabled="True"
								FocusVisualStyle="{x:Null}">
          <Image Source="{DynamicResource Image_Redo}" Height="32"/>
        </Button>

        <Separator Margin="9,3"/>

        <ToggleButton IsChecked="{Binding ActiveEdiDocument.WordWrap, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                      CommandParameter="{x:Static vm:ToggleEditorOption.WordWrap}"
                      Command="{Binding ToggleEditorOptionCommand}"
                      ToolTip="{x:Static cmdLabel:Strings.STR_ToggleEditorOptionCmd_WordWrap_TT}"
                      ToolTipService.ShowOnDisabled="True"
											FocusVisualStyle="{x:Null}"
                      >
          <Image Source="{DynamicResource Image_WordWrap}" Height="32"/>
        </ToggleButton>
        <ToggleButton IsChecked="{Binding ActiveEdiDocument.ShowLineNumbers, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                      CommandParameter="{x:Static vm:ToggleEditorOption.ShowLineNumber}"
                      Command="{Binding ToggleEditorOptionCommand}"
                      ToolTip="{x:Static cmdLabel:Strings.STR_ToggleEditorOptionCmd_ShowLineNumbers_TT}"
                      ToolTipService.ShowOnDisabled="True"
											FocusVisualStyle="{x:Null}"
                      >
          <Image Source="{DynamicResource Image_ShowLineNumbers}" Height="32"/>
        </ToggleButton>
        <ToggleButton IsChecked="{Binding ActiveEdiDocument.ShowEndOfLine, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                      Command="{Binding ToggleEditorOptionCommand}"
                      CommandParameter="{x:Static vm:ToggleEditorOption.ShowEndOfLine}"
                      ToolTip="{x:Static cmdLabel:Strings.STR_ToggleEditorOptionCmd_ShowEndOfLine_TT}"
                      ToolTipService.ShowOnDisabled="True"
											FocusVisualStyle="{x:Null}"
                      >
          <Image Source="{DynamicResource Image_EndOfLine}" Height="32"/>
        </ToggleButton>

        <ToggleButton IsChecked="{Binding ActiveEdiDocument.ShowSpaces, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                      Command="{Binding ToggleEditorOptionCommand}"
                      CommandParameter="{x:Static vm:ToggleEditorOption.ShowSpaces}"
                      ToolTip="{x:Static cmdLabel:Strings.STR_ToggleEditorOptionCmd_ShowSpaces_TT}"
                      ToolTipService.ShowOnDisabled="True"
											FocusVisualStyle="{x:Null}"
                      >
          <Image Source="{DynamicResource Image_Space}" Height="32"/>
        </ToggleButton>
        <ToggleButton IsChecked="{Binding ActiveEdiDocument.ShowTabs, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                      Command="{Binding ToggleEditorOptionCommand}"
                      CommandParameter="{x:Static vm:ToggleEditorOption.ShowTabs}"
                      ToolTip="{x:Static cmdLabel:Strings.STR_ToggleEditorOptionCmd_ShowTabs_TT}"
                      ToolTipService.ShowOnDisabled="True"
											FocusVisualStyle="{x:Null}"
                      >
          <Image Source="{DynamicResource Image_Tabs}" Height="32"/>
        </ToggleButton>

        <Separator Visibility="{Binding Path=ActiveDocument, Mode=OneWay, Converter={adconv:ActiveDocumentToVisibilityConverter}}"
                   Margin="9,3" />

        <!-- Select Highlighting pattern combobox is visible only if there is an active document (otherwise there ain't much to highlight) -->
        <ComboBox SelectedItem="{Binding ActiveEdiDocument.HighlightingDefinition}"
				          ItemsSource="{Binding Source={x:Static avalonEdit:HighlightingManager.Instance}, Path=HighlightingDefinitionsSortedByName}"
                  Visibility="{Binding Path=ActiveDocument, Mode=OneWay, Converter={adconv:ActiveDocumentToVisibilityConverter}}"
                  MinWidth="100"
                  Margin="3,0"
                  ToolTip="{x:Static cmdLabel:Strings.STR_ToggleEditorOptionCmd_HighlightingDefinition_TT}"
                  ToolTipService.ShowOnDisabled="True"
									FocusVisualStyle="{x:Null}"
        />
        <Button Command="cmd:AppCommand.DisableHighlighting" SnapsToDevicePixels="True"
                Margin="3,0"
                Visibility="{Binding Path=ActiveDocument, Mode=OneWay, Converter={adconv:ActiveDocumentToVisibilityConverter}}"
                ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}"
                ToolTipService.ShowOnDisabled="True"
								FocusVisualStyle="{x:Null}">
          <Image Source="{DynamicResource Image_SyntaxHighlighting}" Height="32"/>
        </Button>
      </ToolBar>
    </ToolBarTray>
  </Grid>
</UserControl>
